package com.yidu.best.stock.stockQuotation.controller;

import java.io.InputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.yidu.best.stock.stockQuotation.domain.StockQuotationVo;
import com.yidu.best.stock.stockQuotation.service.StockQuotationService;

@Controller
@RequestMapping("/stock/")
public class StockQuotationController {
	@Autowired
	private StockQuotationService stockQuotationService;

	public StockQuotationController() {
		super();
	}

	public StockQuotationController(StockQuotationService stockQuotationService) {
		super();
		this.stockQuotationService = stockQuotationService;
	}

	
	public StockQuotationService getStockQuotationService() {
		return stockQuotationService;
	}

	public void setStockQuotationService(StockQuotationService stockQuotationService) {
		this.stockQuotationService = stockQuotationService;
	}

	
	/**
	 * 加载股票数据信息
	 * @return
	 */
	@RequestMapping(value="stockPlate")
	public String stockPlateList() {
		return "sys/stock/stockList";
		
	}
	/**
	 * 查找所有股票行情数据
	 * @param stockPlateVo 股票对象
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="stockPlates",method=RequestMethod.GET)
	public Map<String, Object> queryStockPlateDate(StockQuotationVo stockPlateVo){
		Map<String, Object> stockPlateMap = stockQuotationService.queryStockPlateByCriteriaWithPage(stockPlateVo);
		return stockPlateMap;
	}
	 @RequestMapping(value="import",method=RequestMethod.POST)
     @ResponseBody
     public String impotr(HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipart = (MultipartHttpServletRequest) request;
        MultipartFile file = multipart.getFile("file");
        String filename = request.getParameter("filename");
        InputStream in = file.getInputStream();
        System.out.println(filename);
         //数据导入
        stockQuotationService.ajaxUploadExcel(in, file);
        in.close();
        return "true";
     }
}
